<template>
  <div>
    <button @click="exportFilesFromServer">从服务器导出压缩包</button>
  </div>
</template>

<script>
import { exportZip } from "../utils/useZip";

export default {
  name: "ExportZipExample",
  methods: {
    async exportFilesFromServer() {
      const files = [];

      // 示例：从服务器获取文件内容
      const response1 = await fetch("	http://127.0.0.1:9000/senior-valve-hub/image/%E5%BF%83%E7%94%B5%E5%9B%BE.jpg");
      console.log(response1);
      console.log(typeof response1);
      const text1 = await response1.text();
      files.push({ name: "file1.jpg", content: text1 });

      const response2 = await fetch("	http://127.0.0.1:9000/senior-valve-hub/image/%E5%BF%83%E7%94%B5%E5%9B%BE.jpg");
      const text2 = await response2.text();
      files.push({ name: "file2.jpg", content: text2 });

      // 导出压缩包
      exportZip(files, "server_files.zip");
    },
  },
};
</script>